<?php
	#############################################################################################
	# Programmer: สมบูรณ์  กองลี																#
	# Email		: hugo8xx@hotmail.com.															#
	#############################################################################################
	
	function f_checkbox($name, $value,$label,$checked=true, $isArray=false) {
		$checkboxName	= ($isArray) ? $name."[".$value."]" : $name;
		$checkboxId		= ($isArray) ? "{$name}_{$value}" : "";
		$check			= ($checked) ? "checked='checked'" : "";

		return "<label><input name=\"$checkboxName\" type=\"checkbox\" id=\"$checkboxId\" value=\"$value\" $check />$label </label>";
	}

	function f_option($value,$label,$selected=false) {
		$select			= ($selected)	? "selected=\"selected\"" : "";
		return "<option value=\"$value\" $select >$label </option>";
	}

	function arrayOptions($haystack,$selected="") {
		$aOptions = array();
		foreach($haystack as $value=>$label) {
			$aOptions[] = f_option($value,$label,$value==$selected);
		}

		return implode("", $aOptions);
	}

	function sqlOptions($sql,$selected="") {
		$sqlOptions = array();
		$query	= mysql_query($sql);
		while($result = mysql_fetch_array($query)) {
			$value = $result['value'];
			$label = $result['label'];
			$sqlOptions[] = f_option($value,$label,$value==$selected);
		}
		mysql_free_result($query);


		return implode("", $sqlOptions);
	}

	function arrayRadios($haystack,$name,$selected="") {
		$arrayRadios	= array();
		foreach($haystack as $value=>$label) {
			$checked = $value==$selected? "checked" : "";
			$arrayRadios[] = "<input name=\"{$name}\" id=\"{$name}\" value=\"{$value}\" type=\"radio\" {$checked} />{$label}";
		}
		return implode("", $arrayRadios);
	}
	
	function arrayCheckBox($haystack,$name,$selected="") {
		$arrayCheck	= array();
		foreach($haystack as $value=>$label) {
			$checked = "";
			if(is_array($selected)) {
				if(in_array( $value,$selected )){
					$checked = "checked";
				}
			}
			$arrayCheck[] = "<input name=\"{$name}\" value=\"{$value}\" type=\"checkbox\" {$checked} />{$label}";
		}
		return implode("", $arrayCheck);
	}
?>